package day4;

import java.util.Scanner;

public class Main2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()) {
            int m = in.nextInt();
            int n = in.nextInt();
            StringBuilder ret = new StringBuilder();
            String table = "0123456789ABCDEF";
            boolean flg = false;
            if(m < 0) {
                m = -m;
                flg = true;
            }
            if(m == 0) {
                ret.append('0');
            }
            while( m != 0) {
                ret.append(table.charAt( m % n));
                m /= n;
            }
            if(flg) {
                ret.append('-');
            }
            ret.reverse();
            System.out.println(ret);
        }
    }
}
